package com.aiit.controller;

import com.aiit.pojo.Job;
import com.aiit.service.JobService;
import com.aiit.util.TableResult;
import com.aiit.vo.PageResultVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: LuTao
 * @Date: 2022/05/09/9:55
 */
@Controller
public class JobController {
    @Autowired
    private JobService jobService;

    @ResponseBody
    @GetMapping("/job/getByConditionInHr/{id}")
    public TableResult<Job> getByConditionInHr(@PathVariable("id") Integer id,
                                               @RequestParam("page") Long page,
                                               @RequestParam("limit")Long limit){

        QueryWrapper<Job> jobQueryWrapper = new QueryWrapper<>();
        jobQueryWrapper.eq("create_hr_id",id);

        Page<Job> jobPage = new Page<>(page,limit);
        Page<Job> pageResult = jobService.page(jobPage,jobQueryWrapper);

        return new TableResult(0,"",pageResult.getTotal(),pageResult.getRecords());
    }

    @ResponseBody
    @GetMapping("/job/getByCondition")
    public TableResult<Job> getByCondition(@RequestParam("page")Long page,
                                           @RequestParam("limit")Long limit,
                                           @RequestParam("job") String job,
                                           @RequestParam(value = "education",required = false) String education,
                                           @RequestParam("startDate")String startDate,
                                           @RequestParam(value = "endDate",required = false) String endDate,
                                           @RequestParam("area")String area,
                                           @RequestParam("business")String business){
//        PageResultVo<Job> pageResultVo = jobService.getByCondition(page, limit, job, education, startDate, endDate, area, business);

        PageResultVo<Job> pageResultVo = jobService.getByCondition(page,limit,job,education,area,business,startDate,endDate);

        return new TableResult(0,"",pageResultVo.getTotal(),pageResultVo.getRecords());
    }

}
